using MEA.AE_Data.Config;

namespace MEA.AE_Data
{
	public class DTC
	{
		public class Env
		{
			public string Env_Signal;

			public string Env_Description;

			public ConfigDTCBase.EDTCSigClass Env_Class;

			public string Env_first_value;

			public string Env_last_value;

			public Env(string env_Signal, string env_Description, ConfigDTCBase.EDTCSigClass env_Class)
			{
				Env_Signal = env_Signal;
				Env_Description = env_Description;
				Env_Class = env_Class;
			}

			public Env(Env e)
			{
				Env_Signal = e.Env_Signal;
				Env_Description = e.Env_Description;
				Env_first_value = e.Env_first_value;
				Env_last_value = e.Env_last_value;
				Env_Class = e.Env_Class;
			}
		}

		public int id;

		public string displaytext;

		public string signal;

		private string min;

		private string max;

		private string npl;

		private string sig;

		public int ErrTyp_first;

		public string ErrTyp_firstText;

		public int ErrTyp_last;

		public string ErrTyp_lastText;

		private bool status;

		public string statusText;

		public int freq;

		private bool cautionlamp;

		public string cautionlampText;

		public Env[] vals = new Env[9];

		public DTC(DTC d)
		{
			id = d.id;
			displaytext = d.displaytext;
			signal = d.signal;
			min = d.min;
			max = d.max;
			npl = d.npl;
			sig = d.sig;
			for (int i = 0; i < d.vals.Length; i++)
			{
				vals[i] = new Env(d.vals[i]);
			}
		}

		public DTC()
		{
			id = 0;
			displaytext = "";
			signal = "";
			min = string.Empty;
			max = string.Empty;
			npl = string.Empty;
			sig = string.Empty;
			vals = new Env[9];
		}

		public DTC(int id, string signal, string displaytext, string max, string min, string sig, string npl, Env[] envs)
		{
			this.id = id;
			this.displaytext = displaytext;
			this.signal = signal;
			this.min = min;
			this.max = max;
			this.npl = npl;
			this.sig = sig;
			vals = envs;
		}

		public override string ToString()
		{
			string text = string.Format("{0:X4}", id) + " " + displaytext.ToString();
			switch (ErrTyp_last)
			{
			case 1:
				text = text + " " + max.ToString();
				break;
			case 2:
				text = text + " " + min.ToString();
				break;
			case 4:
				text = text + " " + sig.ToString();
				break;
			case 8:
				text = text + " " + npl.ToString();
				break;
			}
			return text;
		}

		public DTC CloneNewStatus(int ErrTyp_first, int ErrTyp_last, bool act, bool cl, byte[] Env_Val_first, byte[] Env_Val_last)
		{
			this.ErrTyp_first = ErrTyp_first;
			switch (this.ErrTyp_first)
			{
			case 1:
				ErrTyp_firstText = max.ToString();
				break;
			case 2:
				ErrTyp_firstText = min.ToString();
				break;
			case 4:
				ErrTyp_firstText = sig.ToString();
				break;
			case 8:
				ErrTyp_firstText = npl.ToString();
				break;
			}
			this.ErrTyp_last = ErrTyp_last;
			switch (this.ErrTyp_last)
			{
			case 1:
				ErrTyp_lastText = max.ToString();
				break;
			case 2:
				ErrTyp_lastText = min.ToString();
				break;
			case 4:
				ErrTyp_lastText = sig.ToString();
				break;
			case 8:
				ErrTyp_lastText = npl.ToString();
				break;
			}
			cautionlamp = cl;
			if (cl)
			{
				cautionlampText = "On";
			}
			else
			{
				cautionlampText = "Off";
			}
			status = act;
			if (act)
			{
				statusText = "active";
			}
			else
			{
				statusText = "not active";
			}
			for (int i = 0; i < 9; i++)
			{
				Env env = vals[i];
				ConfigDTCBase.SSigClass sSigClass = ConfigData.SigClass[(int)env.Env_Class];
				env.Env_first_value = sSigClass.GetValAsString(Env_Val_first[i]);
				env.Env_last_value = sSigClass.GetValAsString(Env_Val_last[i]);
				vals[i] = env;
			}
			return this;
		}

		public DTC CloneNewStatusXML(int ErrTyp_first, int ErrTyp_last, string active, string cl, int freq, string[] Env_Val_first, string[] Env_Val_last, string[] description, string[] unit)
		{
			this.ErrTyp_first = ErrTyp_first;
			switch (this.ErrTyp_first)
			{
			case 1:
				ErrTyp_firstText = max.ToString();
				break;
			case 2:
				ErrTyp_firstText = min.ToString();
				break;
			case 4:
				ErrTyp_firstText = sig.ToString();
				break;
			case 8:
				ErrTyp_firstText = npl.ToString();
				break;
			}
			this.ErrTyp_last = ErrTyp_last;
			switch (this.ErrTyp_last)
			{
			case 1:
				ErrTyp_lastText = max.ToString();
				break;
			case 2:
				ErrTyp_lastText = min.ToString();
				break;
			case 4:
				ErrTyp_lastText = sig.ToString();
				break;
			case 8:
				ErrTyp_lastText = npl.ToString();
				break;
			}
			this.freq = freq;
			cautionlampText = cl;
			if (cl == "On")
			{
				cautionlamp = true;
			}
			else
			{
				cautionlamp = false;
			}
			statusText = active;
			if (active == "active")
			{
				status = true;
			}
			else
			{
				status = false;
			}
			for (int i = 0; i < 9; i++)
			{
				vals[i].Env_Description = description[i];
				vals[i].Env_first_value = Env_Val_first[i];
				vals[i].Env_last_value = Env_Val_last[i];
			}
			return this;
		}

		public object[] row()
		{
			return new object[5]
			{
				status,
				cautionlamp,
				string.Format("{0:x4}", id),
				displaytext,
				ErrTyp_lastText
			};
		}
	}
}
